

from selenium import webdriver
import time


#data= ['光荣之路自动化测试||艾瑞克老师','性能测试||工具','selenium自动化测试||浏览器']
with open('data.txt',encoding='utf-8') as fp:
    for line in fp:
        #print(1,line.strip())
        test_data= line.strip()
        search_word= test_data.split('||')[0]
        assert_word= test_data.split('||')[1]
        driver= webdriver.Chrome(executable_path='D:\\pythonglr\\python\\driver\\chromedriver.exe')
        driver.get('https://www.sogou.com')
        driver.find_element_by_id('query').send_keys(search_word)
        driver.find_element_by_id('stb').click()


        time.sleep(3)
        try:
            assert assert_word in driver.page_source
        except Exception:
            print('断言失败：%s' %assert_word)
        driver.close()

